package casia.isiteam.springbootshiro.controller;


import casia.isiteam.springbootshiro.model.po.test.Girl;
import casia.isiteam.springbootshiro.model.po.test.GirlRepository;
import casia.isiteam.springbootshiro.properties.result.HttpResult;
import casia.isiteam.springbootshiro.service.GirlService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import javax.validation.Valid;
import java.util.List;

/**
 * Author wzy
 * Date 2017/7/26 14:20
 */
@RestController
public class GirlController {
    private final static Logger logger = LoggerFactory.getLogger(GirlController.class);
    @Autowired
    private GirlRepository girlRepository;
    @Autowired
    private GirlService girlService;

    @RequiresRoles("conservator")
    @ApiOperation(value="查询girls所有列表", notes="")
    @GetMapping(value="/select_girls")
    public Object girlsList(HttpServletRequest request) throws Exception{

        return HttpResult.sucess(girlRepository.findAll());
    }

    @ApiOperation(value="获取girl详细信息", notes="根据id来获取girl详细信息")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "Interger")
    @GetMapping(value="/search_girls/{id}")
    public Object search_girl(@PathVariable Integer id) throws Exception{
        return HttpResult.sucess(girlRepository.findOne(id));
    }

    @ApiOperation(value="增加girl", notes="增加girl")
    @ApiImplicitParam(name = "age", value = "年龄", required = true, dataType = "Interger")
    @GetMapping(value="/add_girl/{age}/{cup_size}")
    public Object add_girl(@PathVariable Integer age,@PathVariable String cup_size) throws Exception{
        Girl girl = new Girl();
        girl.setAge(age);
        girl.setCupSize(cup_size);
        return HttpResult.sucess(girlRepository.save(girl));
    }
    @ApiOperation(value="跳转index.html页面", notes="跳转index.html页面")
    @RequestMapping(value="/in")
    public Object index() throws Exception{
        return "index";
    }
}
